#ifndef __CALCULATE_HASH__
#define __CALCULATE_HASH__
#include <my_header.h>
#include <openssl/sha.h>
#include "mysql.h"
#include "down_and_up.h"

// 计算文件SHA-256哈希
void sha256_file(const char *filename, char *output_hash) {
    FILE *fp = fopen(filename, "rb");
    unsigned char hash[SHA256_DIGEST_LENGTH];
    SHA256_CTX ctx;
    SHA256_Init(&ctx);

    char buffer[1024];
    size_t bytes;
    while ((bytes = fread(buffer, 1, sizeof(buffer), fp))) {
        SHA256_Update(&ctx, buffer, bytes);
    }
    SHA256_Final(hash, &ctx);
    fclose(fp);

    for (int i = 0; i < SHA256_DIGEST_LENGTH; i++) {
        sprintf(output_hash + (i * 2), "%02x", hash[i]);
    }
    output_hash[64] = '\0';
}
#endif
